import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-09-15
 * Time: 14:13
 */
public class test4 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int num:nums){
            set.add(num);
        }
        int ret = 0;
        for(int num:set){
            if(!set.contains(num-1)){
                int currentNum = num;
                int currentLength = 1;
                while(set.contains(currentNum+1)){
                    currentNum += 1;
                    currentLength += 1;
                }
                ret = Math.max(ret,currentLength);
            }
        }
        return ret;
    }
}
